unit Class_YotoDict;
//YXC_2011_12_17_15_34_52


interface
uses
  Classes,SysUtils,Uni;
type
  TYotoDict=class(TObject)
  public
    DictIdex:Integer;
    DictCode:string;
    DictName:string;
    DictMemo:string;
  public
    procedure InsertDB(AUniConnection:TUniConnection);
    procedure UpdateDB(AUniConnection:TUniConnection);
    procedure DeleteDB(AUniConnection:TUniConnection);
  public
    class function StrsDB(ASQL:string;AUniConnection:TUniConnection):TStringList;
    class function ReadDS(AUniQueryA:TUniQuery):TYotoDict;
  end;

implementation

{ TYotoDict }

procedure TYotoDict.DeleteDB(AUniConnection: TUniConnection);
var
  UniSQLA:TUniSQL;
begin
  try
    UniSQLA:=TUniSQL.Create(nil);
    UniSQLA.Connection:=AUniConnection;

    UniSQLA.SQL.Add('DELETE FROM TBL_YOTO_DICT WHERE DICT_IDEX=:DICT_IDEX');
    UniSQLA.ParamByName('DICT_IDEX').Value:=DictIdex;
    UniSQLA.Execute;

  finally
    FreeAndNil(UniSQLA);
  end;
end;

procedure TYotoDict.InsertDB(AUniConnection: TUniConnection);
var
  //UniQueryA:TUniQuery;
  UniSQLA:TUniSQL;
begin
  {try
    UniQueryA:=TUniQuery.Create(nil);
    UniQueryA.Connection:=AUniConnection;
    UniQueryA.SQL.Clear;
    UniQueryA.SQL.Add('INSERT INTO TBL_YOTO_DICT (DICT_IDEX,DICT_CODE,DICT_NAME,DICT_MEMO) VALUES (:DICT_IDEX,:DICT_CODE,:DICT_NAME,:DICT_MEMO)');
    UniQueryA.ParamByName('DICT_IDEX').Value:=DictIdex;
    UniQueryA.ParamByName('DICT_CODE').Value:=DictCode;
    UniQueryA.ParamByName('DICT_NAME').Value:=DictName;
    UniQueryA.ParamByName('DICT_MEMO').Value:=DictMemo;
    UniQueryA.Execute;
  finally
    FreeAndNil(UniQueryA);
  end;}


  try
    UniSQLA:=TUniSQL.Create(nil);
    UniSQLA.Connection:=AUniConnection;
    UniSQLA.SQL.Clear;
    UniSQLA.SQL.Add('INSERT INTO TBL_YOTO_DICT (DICT_IDEX,DICT_CODE,DICT_NAME,DICT_MEMO) VALUES (:DICT_IDEX,:DICT_CODE,:DICT_NAME,:DICT_MEMO)');
    UniSQLA.ParamByName('DICT_IDEX').Value:=DictIdex;
    UniSQLA.ParamByName('DICT_CODE').Value:=DictCode;
    UniSQLA.ParamByName('DICT_NAME').Value:=DictName;
    UniSQLA.ParamByName('DICT_MEMO').Value:=DictMemo;
    UniSQLA.Execute;
  finally
    FreeAndNil(UniSQLA);
  end;
end;

class function TYotoDict.ReadDS(AUniQueryA: TUniQuery): TYotoDict;
begin
  Result:=TYotoDict.Create;
  with Result do
  begin
    DictIdex:=AUniQueryA.FieldByName('DICT_IDEX').AsInteger;
    DictCode:=AUniQueryA.FieldByName('DICT_CODE').AsString;
    DictName:=AUniQueryA.FieldByName('DICT_NAME').AsString;
    DictMemo:=AUniQueryA.FieldByName('DICT_MEMO').AsString;
  end;
end;

class function TYotoDict.StrsDB(ASQL: string;
  AUniConnection: TUniConnection): TStringList;
var
  UniQueryA:TUniQuery;
  ObjA:TYotoDict;
begin
  Result:=nil;
  try
    UniQueryA:=TUniQuery.Create(nil);
    UniQueryA.Connection:=AUniConnection;
    UniQueryA.SQL.Clear;
    UniQueryA.SQL.Add(ASQL);
    UniQueryA.Open;
    if UniQueryA.RecordCount=0 then Exit;
    Result:=TStringList.Create;
    UniQueryA.First;
    while not UniQueryA.Eof  do
    begin
      ObjA:=nil;
      ObjA:=ReadDS(UniQueryA);
      if ObjA=nil then Continue;
      Result.AddObject('',ObjA);
      UniQueryA.Next;
    end;
  finally
    FreeAndNil(UniQueryA);
  end;
end;

procedure TYotoDict.UpdateDB(AUniConnection: TUniConnection);
var
  UniSQLA:TUniSQL;
begin
  try
    UniSQLA:=TUniSQL.Create(nil);
    UniSQLA.Connection:=AUniConnection;

    UniSQLA.SQL.Clear;
    UniSQLA.SQL.Add('UPDATE TBL_YOTO_DICT SET DICT_CODE=:DICT_CODE,DICT_NAME=:DICT_NAME,DICT_MEMO=:DICT_MEMO WHERE DICT_IDEX=:DICT_IDEX');

    UniSQLA.ParamByName('DICT_IDEX').Value:=DictIdex;
    UniSQLA.ParamByName('DICT_CODE').Value:=DictCode;
    UniSQLA.ParamByName('DICT_NAME').Value:=DictName;
    UniSQLA.ParamByName('DICT_MEMO').Value:=DictMemo;

    UniSQLA.Execute;
  finally
    FreeAndNil(UniSQLA);
  end;
end;

end.
